﻿var hid=getvl("hid");
var tid=getvl("tid");
var memberMoney="";
   $(function(){
   	    if(hid!=''){
   	    	hselect(hid);
   	    }else if(tid!=''){
   	    	recommend(tid);
   	    }
   });
	
//会员够买信息
    function hselect(){
	$("#huiyuanchaxun").html("");
	$.ajax({
		url: urlcore + "/api/member/selectOne?id="+hid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				if(data.data!=null && data.data!=''){
		var huiyuanchaxun='<ul>'+
		'<li>'+
		'套餐'+
			'<h6>'+data.data.name+'</h6>'+
		'</li>'+
		'<li>'+
		'时间'+
			'<h6>'+data.data.memberTime+'个月</h6>'+
			'</li>'+
		'<li>'+
			'价格'+
			'<h6><em>&yen;'+data.data.memberMoney+'</em></h6>'+
			'</li>'+
	'</ul>';
	memberMoney=data.data.memberMoney;
//	alert(data.data.price);
        $("#querenzhifu").val("确认支付("+memberMoney+"元)");
	    $("#huiyuanchaxun").append(huiyuanchaxun);
				}
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
	 
    }

 function querenzhifuss(){  //会员的购买方式
 	 var val=$('input:radio[name="radio1"]:checked').val();
	     if(val==null){
	     	alert("未选择支付方式");
	     	return false;
	     }else{
	     	 if(val=="01"){
                yuezhifu();	 	
	     	 }else if(val=="02"){
	     	 	callpay();
	     	 }
	     }
 }

zhanghuxinxi();
function  zhanghuxinxi(){
	    $("#zhanghu").html("");
   	$.ajax({
		url: urlcore + "/api/userAccount/selectUserAccountDetails",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
              $("#zhanghu").html("&yen;"+data.data.balanceMoney);
            // $("#jinbi").html(data.data.userGold);
			}
		},
		error:function() {
			/* Act on the event*/
			alert("error");
		}
	});	
}

//微信支付
function zhifuweixin(){
	var url2="";
		if(hid!=null&& hid!=""){
	url2="/api/pay/wxpay2?userId="+uuuuid+"&memberId="+hid;
		}else if(tid!=null && tid!=""){
	url2="/api/pay/wxpay2?userId="+uuuuid+"&incrementServiceId="+tid;		
		}
      if(url2!=""){
				$.ajax({
					url: urlcore+url2,
					type: "get",
					dataType: 'json',
					contentType: "application/json;charset=utf-8",
					success:function(data){		
					var d = data.data;
					 WeixinJSBridge.invoke(
					    'getBrandWCPayRequest',
					    {
				           "appId":d.appId,    
				           "timeStamp":d.timeStamp,        
				           "nonceStr":d.nonceStr, 
				           "package":d.package,     
				           "signType":"MD5",        
				           "paySign":d.paySign 
				       },
					    function (res){
					         if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					         	   alert("支付成功");
					         }else{
					         	alert("支付失败");
					         }
					    });
				},
					error:function() {
						/* Act on the event */
						alert("error");
					}
				});	
	}
        }



 function callpay(){
		if (typeof WeixinJSBridge == "undefined"){
			    if (document.addEventListener){
		document.addEventListener('WeixinJSBridgeReady', zhifuweixin,false);
			    }else if (document.attachEvent){
        document.attachEvent('WeixinJSBridgeReady', zhifuweixin);
		document.attachEvent('onWeixinJSBridgeReady', zhifuweixin);
			    }
			    }else{
			        zhifuweixin();
			    }
			}
//余额支付
function yuezhifu(){
	 if(uuuuid!=""){
	 $.ajax({
		url: urlcore + "/api/user/selectOne?id="+uuuuid,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				if(data.data!=null && data.data!=""){
					if(data.data.payPwd!="" || data.data.payPwd!=null){
		               sessionStorage.setItem("orids","");
	                   sessionStorage.setItem("hid",hid);
	                   sessionStorage.setItem("tid",tid);
		window.location.href="zhifumimatankuang.html";
					}else{
						alert("未设置支付密码");
	             window.location.href="../buy/12.7.0shezhi.html";
					}
				}
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
	  	
	 }
}





 function recommend(tida){
			$("#huiyuanchaxun").html("");
      $.ajax({
		url: urlcore + "/api/incrementService/selectOne?id="+tida,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				if(data.data!=null && data.data!=''){
		var huiyuanchaxun='<ul>'+
		'<li>'+
		'套餐'+
			'<h6>'+data.data.title+'</h6>'+
		'</li>'+
		'<li>'+
		'有效时间'+
			'<h6>'+data.data.validityTime+'个月</h6>'+
			'</li>'+
		'<li>'+
			'价格'+
			'<h6><em>&yen;'+data.data.price+'</em></h6>'+
			'</li>'+
	'</ul>';
	memberMoney=data.data.price;
	               //alert(data.data.price)
	     $("#querenzhifu").val("确认支付("+memberMoney+"元)");
	     
	    $("#huiyuanchaxun").append(huiyuanchaxun);
				}
			}
		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});
	
    }
 